﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.9.1.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->

<title>維護環境</title>

<script type="text/javascript">

var tmp="";

$(document).ready(function() {
	if ($.cookie("userId") == null) {
		alert("請先登入系統");
		location.assign("index.html");
	} else {
		$("#a_form #loginUser").val( $.cookie("userId") );
		$("#a_form #isSU").val( $.cookie("isSU") );
		/*	先查詢有那些子系統供 Select	*/
		querySubSys("env");
		
		/*	綁定 下拉吧 選擇的事件 */
		selectSubSys("QueryEnv");
		
		$("#gd").jqGrid({
		   	colNames:["環境ID","環境名稱","Web Console","自身層級","預先部署"],
		   	colModel:[{	/*	環境ID	*/
		   			name:"envId",
		   			index:"envId",
		   			editable:true,
		   			editrules:{ required:true }
		   		}, {	/*	環境名稱	*/
		   			name:"envName",
		   			index:"envName",
		   			editable:true,
		   			editrules:{ required:true }
		   		},{
		   	       name:'webConsole',index:'webConsole',resizable:true,   
		   	       align:"left",sorttype:"text",editable:true,edittype:"select" ,editrules:{required:true}
		   	    }, {	/*	自身層級	*/
		   			name:"selfClass",
		   			formatter:'integer', formatoptions:{defaultValue: '1'},
		   			editable:true,
		   			editrules:{ required:true }
		   		}, {	/*	預先部署	*/
		   			name:"preClass",
		   			formatter:'integer', formatoptions:{defaultValue: '0'},
		   			editable:true,
		   			editrules:{ required:true }
		   		}
		   	],
		   	rowNum: 6,
		   	forceFit: true,
		   	pager: "#pager",
			rownumbers: true,
		   	viewrecords: true,	
			caption: "維護環境"
		}).jqGrid("navGrid","#pager",{add:true,edit:true,del:true,search:false,refresh:false},
			{	
				/* Edit
					按下送出後要完成下列功能
					1. 畫面更新為新輸入的資料
					2. 後端更改新值成功 
				*/
				url: "ManipulateGridEnv",
				mtype: "POST",
				afterShowForm : function(formid) {
					var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
					sel_id = $("#gd").jqGrid('getCell', sel_id, 'webConsole');
					$.post('QueryWCL',{fc:'2',bssId:$("table#parTable #bss option:selected").val(), subSysId: $("table#parTable #subsys option:selected").val() },function(reses) {
						$("select.FormElement option").remove();
						$.each( reses, function(i, res) {
							tmp = "";
							if ( res.strA == sel_id) { tmp="SELECTED"; }
							$("select.FormElement").append("<option id='"+res.intA+"' "+tmp+" >"+res.strA+"</option>");	
						});
					},"JSON");
				},
				
				editData:{
					bssId: function() { return $("table#parTable #bss option:selected").val();},
					subSysId: function() { return $("table#parTable #subsys option:selected").val(); },
					webConsole: function() { return $("select.FormElement option:selected").attr("id"); },
					currentUser: function() { return $.cookie("userId"); }
				}		
			},
			{	// Add
				url: "ManipulateGridEnv",
				mtype: "POST",
				afterShowForm : function(formid) {
					var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
					sel_id = $("#gd").jqGrid('getCell', sel_id, 'webConsole');
					$.post('QueryWCL',{fc:'2',bssId:$("table#parTable #bss option:selected").val(), subSysId: $("table#parTable #subsys option:selected").val() },function(reses) {
						$("select.FormElement option").remove();
						$.each( reses, function(i, res) {
							tmp = "";
							if ( res.strA == sel_id) { tmp="SELECTED"; }
							$("select.FormElement").append("<option id='"+res.intA+"' "+tmp+" >"+res.strA+"</option>");	
						});
					},"JSON");
				},
				editData: {
					bssId: function() { return $("table#parTable #bss option:selected").val();},
					subSysId: function() { return $("table#parTable #subsys option:selected").val(); },
					currentUser: function() { return $.cookie("userId"); }
				}
			},
			{	// Delete
				url: "ManipulateGridEnv",
				mtype: "POST",
				delData: { 
					bssId: function() { return $("table#parTable #bss option:selected").val();},
					subSysId: function() { return $("table#parTable #subsys option:selected").val(); },
					envId: function() {
						var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
						return $("#gd").jqGrid('getCell', sel_id, 'envId');
					},
					currentUser: function() { return $.cookie("userId"); }
				}
			});
		
			reconfigPermissions('2','gd');
			initPage("維護環境");
	}
}).tooltip();
</script>

</head>
<body>
	<div id="header"></div>
	<p>
	<form id="a_form">
		<input type="hidden" id="fc" name="fc" />
		<input type="hidden" id="subSysId" name="subSysId" />
		<input type="hidden" id="loginUser" name="loginUser" />
		<input type="hidden" id="isSU" name="isSU" />
	</form>
	<br/>

	<table id="parTable">
		<tr>
			<th class="right"><label for="bss">系統：</label></th>
			<td><select id="bss"><option>MBMS</option></select></td>
		</tr>
		<tr>
			<th class="right"><label for="subsys">子系統：</label></th>
			<td><select id="subsys"><option id='dOpt'>--請選擇--</option></select></td>
		</tr>
	</table>

	<p>
<hr/>
<p>
<table id="gd"></table>
<div id="pager"></div>


</body>
</html>